package extreme.tddscaffold.service.impl;

import extreme.tddscaffold.Item;
import extreme.tddscaffold.service.IPriceCalc;

public class BackstageBrieItemPriceCalcImpl implements IPriceCalc {
    @Override
    public void calcItemPrice(Item item) {
        int newPrice = 0;
        if (item.getUpdatedSellIn() <= 0) {
            item.setUpdatedQuality(newPrice);
            return;
        }

        if (item.getUpdatedSellIn() < 5) {
            if (item.getSellIn() > 5) {
                newPrice = item.getQuality() +
                        (2 * (item.getSellIn() - 5)) + 3 * (5 - item.getUpdatedSellIn());
            } else {
                newPrice = item.getQuality() + 3 * (5 - item.getUpdatedSellIn());
            }
        } else {
            newPrice = item.getQuality() +
                    (2 * (item.getSellIn() - item.getUpdatedSellIn()));
        }
        item.setUpdatedQuality(newPrice <= 50 ? newPrice : 50);
    }
}
